package za.co.smartmi.dao.impl;

import za.co.smartmi.dao.ClientDao;
import za.co.smartmi.dao.exceptions.ClientDaoException;
import java.util.Date;
import java.util.List;
import javax.sql.DataSource;
import java.sql.ResultSet;
import java.sql.SQLException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.jdbc.core.simple.ParameterizedRowMapper;
import org.springframework.stereotype.Repository;
import org.springframework.transaction.annotation.Transactional;
import za.co.smartmi.dao.support.JdbcGenericDao;
import za.co.smartmi.model.Client;
import za.co.smartmi.model.ClientPk;

@Repository
public class ClientDaoImpl extends JdbcGenericDao implements ParameterizedRowMapper<Client>, ClientDao
{
    
        @Autowired
        public void setDataSource(DataSource dataSource) {
                setJdbcTemplate(new JdbcTemplate(dataSource));
	}
        
	/**
	 * Method 'insert'
	 * 
	 * @param dto
	 * @return ClientPk
	 */
	@Transactional
	public ClientPk insert(Client dto)
	{
		getJdbcTemplate().update("INSERT INTO " + getTableName() + " ( clientid, firstname, surname, idno, dob, title, mobile, hphone, wphone, email1, email2, postaddr1, postaddr2, postaddr3, postcode, physaddr1, physaddr2, physaddr3, notes, type, status, startdate, enddate, csys, cdate, usys, udate ) VALUES ( ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ? )",dto.getClientid(),dto.getFirstname(),dto.getSurname(),dto.getIdno(),dto.getDob(),dto.getTitle(),dto.getMobile(),dto.getHphone(),dto.getWphone(),dto.getEmail1(),dto.getEmail2(),dto.getPostaddr1(),dto.getPostaddr2(),dto.getPostaddr3(),dto.getPostcode(),dto.getPhysaddr1(),dto.getPhysaddr2(),dto.getPhysaddr3(),dto.getNotes(),dto.getType(),dto.getStatus(),dto.getStartdate(),dto.getEnddate(),dto.getCsys(),dto.getCdate(),dto.getUsys(),dto.getUdate());
		return dto.createPk();
	}

	/** 
	 * Updates a single row in the client table.
	 */
	@Transactional
	public void update(ClientPk pk, Client dto) throws ClientDaoException
	{
		getJdbcTemplate().update("UPDATE " + getTableName() + " SET clientid = ?, firstname = ?, surname = ?, idno = ?, dob = ?, title = ?, mobile = ?, hphone = ?, wphone = ?, email1 = ?, email2 = ?, postaddr1 = ?, postaddr2 = ?, postaddr3 = ?, postcode = ?, physaddr1 = ?, physaddr2 = ?, physaddr3 = ?, notes = ?, type = ?, status = ?, startdate = ?, enddate = ?, csys = ?, cdate = ?, usys = ?, udate = ? WHERE clientid = ?",dto.getClientid(),dto.getFirstname(),dto.getSurname(),dto.getIdno(),dto.getDob(),dto.getTitle(),dto.getMobile(),dto.getHphone(),dto.getWphone(),dto.getEmail1(),dto.getEmail2(),dto.getPostaddr1(),dto.getPostaddr2(),dto.getPostaddr3(),dto.getPostcode(),dto.getPhysaddr1(),dto.getPhysaddr2(),dto.getPhysaddr3(),dto.getNotes(),dto.getType(),dto.getStatus(),dto.getStartdate(),dto.getEnddate(),dto.getCsys(),dto.getCdate(),dto.getUsys(),dto.getUdate(),pk.getClientid());
	}

	/** 
	 * Deletes a single row in the client table.
	 */
	@Transactional
	public void delete(ClientPk pk) throws ClientDaoException
	{
		getJdbcTemplate().update("DELETE FROM " + getTableName() + " WHERE clientid = ?",pk.getClientid());
	}

	/**
	 * Method 'mapRow'
	 * 
	 * @param rs
	 * @param row
	 * @throws SQLException
	 * @return Client
	 */
	public Client mapRow(ResultSet rs, int row) throws SQLException
	{
		Client dto = new Client();
		dto.setClientid( new Integer( rs.getInt(1) ) );
		dto.setFirstname( rs.getString( 2 ) );
		dto.setSurname( rs.getString( 3 ) );
		dto.setIdno( rs.getString( 4 ) );
		dto.setDob( rs.getDate(5 ) );
		dto.setTitle( rs.getString( 6 ) );
		dto.setMobile( rs.getString( 7 ) );
		dto.setHphone( rs.getString( 8 ) );
		dto.setWphone( rs.getString( 9 ) );
		dto.setEmail1( rs.getString( 10 ) );
		dto.setEmail2( rs.getString( 11 ) );
		dto.setPostaddr1( rs.getString( 12 ) );
		dto.setPostaddr2( rs.getString( 13 ) );
		dto.setPostaddr3( rs.getString( 14 ) );
		dto.setPostcode( rs.getString( 15 ) );
		dto.setPhysaddr1( rs.getString( 16 ) );
		dto.setPhysaddr2( rs.getString( 17 ) );
		dto.setPhysaddr3( rs.getString( 18 ) );
		dto.setNotes( rs.getString( 19 ) );
		dto.setType( rs.getString( 20 ) );
		dto.setStatus( rs.getString( 21 ) );
		dto.setStartdate( rs.getDate(22 ) );
		dto.setEnddate( rs.getDate(23 ) );
		dto.setCsys( rs.getString( 24 ) );
		dto.setCdate( rs.getDate(25 ) );
		dto.setUsys( rs.getString( 26 ) );
		dto.setUdate( rs.getDate(27 ) );
		return dto;
	}

	/**
	 * Method 'getTableName'
	 * 
	 * @return String
	 */
	public String getTableName()
	{
		return "smartMI.client";
	}

	/** 
	 * Returns all rows from the client table that match the criteria 'clientid = :clientid'.
	 */
	@Transactional
	public Client findByPrimaryKey(Integer clientid) throws ClientDaoException
	{
		try {
			List<Client> list = getJdbcTemplate().query("SELECT clientid, firstname, surname, idno, dob, title, mobile, hphone, wphone, email1, email2, postaddr1, postaddr2, postaddr3, postcode, physaddr1, physaddr2, physaddr3, notes, type, status, startdate, enddate, csys, cdate, usys, udate FROM " + getTableName() + " WHERE clientid = ?", this,clientid);
			return list.size() == 0 ? null : list.get(0);
		}
		catch (Exception e) {
			throw new ClientDaoException("Query failed", e);
		}
		
	}

	/** 
	 * Returns all rows from the client table that match the criteria ''.
	 */
	@Transactional
	public List<Client> findAll() throws ClientDaoException
	{
		try {
			return getJdbcTemplate().query("SELECT clientid, firstname, surname, idno, dob, title, mobile, hphone, wphone, email1, email2, postaddr1, postaddr2, postaddr3, postcode, physaddr1, physaddr2, physaddr3, notes, type, status, startdate, enddate, csys, cdate, usys, udate FROM " + getTableName() + " ORDER BY clientid", this);
		}
		catch (Exception e) {
			throw new ClientDaoException("Query failed", e);
		}
		
	}

	/** 
	 * Returns all rows from the client table that match the criteria 'clientid = :clientid'.
	 */
	@Transactional
	public List<Client> findWhereClientidEquals(Integer clientid) throws ClientDaoException
	{
		try {
			return getJdbcTemplate().query("SELECT clientid, firstname, surname, idno, dob, title, mobile, hphone, wphone, email1, email2, postaddr1, postaddr2, postaddr3, postcode, physaddr1, physaddr2, physaddr3, notes, type, status, startdate, enddate, csys, cdate, usys, udate FROM " + getTableName() + " WHERE clientid = ? ORDER BY clientid", this,clientid);
		}
		catch (Exception e) {
			throw new ClientDaoException("Query failed", e);
		}
		
	}

	/** 
	 * Returns all rows from the client table that match the criteria 'firstname = :firstname'.
	 */
	@Transactional
	public List<Client> findWhereFirstnameEquals(String firstname) throws ClientDaoException
	{
		try {
			return getJdbcTemplate().query("SELECT clientid, firstname, surname, idno, dob, title, mobile, hphone, wphone, email1, email2, postaddr1, postaddr2, postaddr3, postcode, physaddr1, physaddr2, physaddr3, notes, type, status, startdate, enddate, csys, cdate, usys, udate FROM " + getTableName() + " WHERE firstname = ? ORDER BY firstname", this,firstname);
		}
		catch (Exception e) {
			throw new ClientDaoException("Query failed", e);
		}
		
	}

	/** 
	 * Returns all rows from the client table that match the criteria 'surname = :surname'.
	 */
	@Transactional
	public List<Client> findWhereSurnameEquals(String surname) throws ClientDaoException
	{
		try {
			return getJdbcTemplate().query("SELECT clientid, firstname, surname, idno, dob, title, mobile, hphone, wphone, email1, email2, postaddr1, postaddr2, postaddr3, postcode, physaddr1, physaddr2, physaddr3, notes, type, status, startdate, enddate, csys, cdate, usys, udate FROM " + getTableName() + " WHERE surname = ? ORDER BY surname", this,surname);
		}
		catch (Exception e) {
			throw new ClientDaoException("Query failed", e);
		}
		
	}

	/** 
	 * Returns all rows from the client table that match the criteria 'idno = :idno'.
	 */
	@Transactional
	public List<Client> findWhereIdnoEquals(String idno) throws ClientDaoException
	{
		try {
			return getJdbcTemplate().query("SELECT clientid, firstname, surname, idno, dob, title, mobile, hphone, wphone, email1, email2, postaddr1, postaddr2, postaddr3, postcode, physaddr1, physaddr2, physaddr3, notes, type, status, startdate, enddate, csys, cdate, usys, udate FROM " + getTableName() + " WHERE idno = ? ORDER BY idno", this,idno);
		}
		catch (Exception e) {
			throw new ClientDaoException("Query failed", e);
		}
		
	}

	/** 
	 * Returns all rows from the client table that match the criteria 'dob = :dob'.
	 */
	@Transactional
	public List<Client> findWhereDobEquals(Date dob) throws ClientDaoException
	{
		try {
			return getJdbcTemplate().query("SELECT clientid, firstname, surname, idno, dob, title, mobile, hphone, wphone, email1, email2, postaddr1, postaddr2, postaddr3, postcode, physaddr1, physaddr2, physaddr3, notes, type, status, startdate, enddate, csys, cdate, usys, udate FROM " + getTableName() + " WHERE dob = ? ORDER BY dob", this,dob);
		}
		catch (Exception e) {
			throw new ClientDaoException("Query failed", e);
		}
		
	}

	/** 
	 * Returns all rows from the client table that match the criteria 'title = :title'.
	 */
	@Transactional
	public List<Client> findWhereTitleEquals(String title) throws ClientDaoException
	{
		try {
			return getJdbcTemplate().query("SELECT clientid, firstname, surname, idno, dob, title, mobile, hphone, wphone, email1, email2, postaddr1, postaddr2, postaddr3, postcode, physaddr1, physaddr2, physaddr3, notes, type, status, startdate, enddate, csys, cdate, usys, udate FROM " + getTableName() + " WHERE title = ? ORDER BY title", this,title);
		}
		catch (Exception e) {
			throw new ClientDaoException("Query failed", e);
		}
		
	}

	/** 
	 * Returns all rows from the client table that match the criteria 'mobile = :mobile'.
	 */
	@Transactional
	public List<Client> findWhereMobileEquals(String mobile) throws ClientDaoException
	{
		try {
			return getJdbcTemplate().query("SELECT clientid, firstname, surname, idno, dob, title, mobile, hphone, wphone, email1, email2, postaddr1, postaddr2, postaddr3, postcode, physaddr1, physaddr2, physaddr3, notes, type, status, startdate, enddate, csys, cdate, usys, udate FROM " + getTableName() + " WHERE mobile = ? ORDER BY mobile", this,mobile);
		}
		catch (Exception e) {
			throw new ClientDaoException("Query failed", e);
		}
		
	}

	/** 
	 * Returns all rows from the client table that match the criteria 'hphone = :hphone'.
	 */
	@Transactional
	public List<Client> findWhereHphoneEquals(String hphone) throws ClientDaoException
	{
		try {
			return getJdbcTemplate().query("SELECT clientid, firstname, surname, idno, dob, title, mobile, hphone, wphone, email1, email2, postaddr1, postaddr2, postaddr3, postcode, physaddr1, physaddr2, physaddr3, notes, type, status, startdate, enddate, csys, cdate, usys, udate FROM " + getTableName() + " WHERE hphone = ? ORDER BY hphone", this,hphone);
		}
		catch (Exception e) {
			throw new ClientDaoException("Query failed", e);
		}
		
	}

	/** 
	 * Returns all rows from the client table that match the criteria 'wphone = :wphone'.
	 */
	@Transactional
	public List<Client> findWhereWphoneEquals(String wphone) throws ClientDaoException
	{
		try {
			return getJdbcTemplate().query("SELECT clientid, firstname, surname, idno, dob, title, mobile, hphone, wphone, email1, email2, postaddr1, postaddr2, postaddr3, postcode, physaddr1, physaddr2, physaddr3, notes, type, status, startdate, enddate, csys, cdate, usys, udate FROM " + getTableName() + " WHERE wphone = ? ORDER BY wphone", this,wphone);
		}
		catch (Exception e) {
			throw new ClientDaoException("Query failed", e);
		}
		
	}

	/** 
	 * Returns all rows from the client table that match the criteria 'email1 = :email1'.
	 */
	@Transactional
	public List<Client> findWhereEmail1Equals(String email1) throws ClientDaoException
	{
		try {
			return getJdbcTemplate().query("SELECT clientid, firstname, surname, idno, dob, title, mobile, hphone, wphone, email1, email2, postaddr1, postaddr2, postaddr3, postcode, physaddr1, physaddr2, physaddr3, notes, type, status, startdate, enddate, csys, cdate, usys, udate FROM " + getTableName() + " WHERE email1 = ? ORDER BY email1", this,email1);
		}
		catch (Exception e) {
			throw new ClientDaoException("Query failed", e);
		}
		
	}

	/** 
	 * Returns all rows from the client table that match the criteria 'email2 = :email2'.
	 */
	@Transactional
	public List<Client> findWhereEmail2Equals(String email2) throws ClientDaoException
	{
		try {
			return getJdbcTemplate().query("SELECT clientid, firstname, surname, idno, dob, title, mobile, hphone, wphone, email1, email2, postaddr1, postaddr2, postaddr3, postcode, physaddr1, physaddr2, physaddr3, notes, type, status, startdate, enddate, csys, cdate, usys, udate FROM " + getTableName() + " WHERE email2 = ? ORDER BY email2", this,email2);
		}
		catch (Exception e) {
			throw new ClientDaoException("Query failed", e);
		}
		
	}

	/** 
	 * Returns all rows from the client table that match the criteria 'postaddr1 = :postaddr1'.
	 */
	@Transactional
	public List<Client> findWherePostaddr1Equals(String postaddr1) throws ClientDaoException
	{
		try {
			return getJdbcTemplate().query("SELECT clientid, firstname, surname, idno, dob, title, mobile, hphone, wphone, email1, email2, postaddr1, postaddr2, postaddr3, postcode, physaddr1, physaddr2, physaddr3, notes, type, status, startdate, enddate, csys, cdate, usys, udate FROM " + getTableName() + " WHERE postaddr1 = ? ORDER BY postaddr1", this,postaddr1);
		}
		catch (Exception e) {
			throw new ClientDaoException("Query failed", e);
		}
		
	}

	/** 
	 * Returns all rows from the client table that match the criteria 'postaddr2 = :postaddr2'.
	 */
	@Transactional
	public List<Client> findWherePostaddr2Equals(String postaddr2) throws ClientDaoException
	{
		try {
			return getJdbcTemplate().query("SELECT clientid, firstname, surname, idno, dob, title, mobile, hphone, wphone, email1, email2, postaddr1, postaddr2, postaddr3, postcode, physaddr1, physaddr2, physaddr3, notes, type, status, startdate, enddate, csys, cdate, usys, udate FROM " + getTableName() + " WHERE postaddr2 = ? ORDER BY postaddr2", this,postaddr2);
		}
		catch (Exception e) {
			throw new ClientDaoException("Query failed", e);
		}
		
	}

	/** 
	 * Returns all rows from the client table that match the criteria 'postaddr3 = :postaddr3'.
	 */
	@Transactional
	public List<Client> findWherePostaddr3Equals(String postaddr3) throws ClientDaoException
	{
		try {
			return getJdbcTemplate().query("SELECT clientid, firstname, surname, idno, dob, title, mobile, hphone, wphone, email1, email2, postaddr1, postaddr2, postaddr3, postcode, physaddr1, physaddr2, physaddr3, notes, type, status, startdate, enddate, csys, cdate, usys, udate FROM " + getTableName() + " WHERE postaddr3 = ? ORDER BY postaddr3", this,postaddr3);
		}
		catch (Exception e) {
			throw new ClientDaoException("Query failed", e);
		}
		
	}

	/** 
	 * Returns all rows from the client table that match the criteria 'postcode = :postcode'.
	 */
	@Transactional
	public List<Client> findWherePostcodeEquals(String postcode) throws ClientDaoException
	{
		try {
			return getJdbcTemplate().query("SELECT clientid, firstname, surname, idno, dob, title, mobile, hphone, wphone, email1, email2, postaddr1, postaddr2, postaddr3, postcode, physaddr1, physaddr2, physaddr3, notes, type, status, startdate, enddate, csys, cdate, usys, udate FROM " + getTableName() + " WHERE postcode = ? ORDER BY postcode", this,postcode);
		}
		catch (Exception e) {
			throw new ClientDaoException("Query failed", e);
		}
		
	}

	/** 
	 * Returns all rows from the client table that match the criteria 'physaddr1 = :physaddr1'.
	 */
	@Transactional
	public List<Client> findWherePhysaddr1Equals(String physaddr1) throws ClientDaoException
	{
		try {
			return getJdbcTemplate().query("SELECT clientid, firstname, surname, idno, dob, title, mobile, hphone, wphone, email1, email2, postaddr1, postaddr2, postaddr3, postcode, physaddr1, physaddr2, physaddr3, notes, type, status, startdate, enddate, csys, cdate, usys, udate FROM " + getTableName() + " WHERE physaddr1 = ? ORDER BY physaddr1", this,physaddr1);
		}
		catch (Exception e) {
			throw new ClientDaoException("Query failed", e);
		}
		
	}

	/** 
	 * Returns all rows from the client table that match the criteria 'physaddr2 = :physaddr2'.
	 */
	@Transactional
	public List<Client> findWherePhysaddr2Equals(String physaddr2) throws ClientDaoException
	{
		try {
			return getJdbcTemplate().query("SELECT clientid, firstname, surname, idno, dob, title, mobile, hphone, wphone, email1, email2, postaddr1, postaddr2, postaddr3, postcode, physaddr1, physaddr2, physaddr3, notes, type, status, startdate, enddate, csys, cdate, usys, udate FROM " + getTableName() + " WHERE physaddr2 = ? ORDER BY physaddr2", this,physaddr2);
		}
		catch (Exception e) {
			throw new ClientDaoException("Query failed", e);
		}
		
	}

	/** 
	 * Returns all rows from the client table that match the criteria 'physaddr3 = :physaddr3'.
	 */
	@Transactional
	public List<Client> findWherePhysaddr3Equals(String physaddr3) throws ClientDaoException
	{
		try {
			return getJdbcTemplate().query("SELECT clientid, firstname, surname, idno, dob, title, mobile, hphone, wphone, email1, email2, postaddr1, postaddr2, postaddr3, postcode, physaddr1, physaddr2, physaddr3, notes, type, status, startdate, enddate, csys, cdate, usys, udate FROM " + getTableName() + " WHERE physaddr3 = ? ORDER BY physaddr3", this,physaddr3);
		}
		catch (Exception e) {
			throw new ClientDaoException("Query failed", e);
		}
		
	}

	/** 
	 * Returns all rows from the client table that match the criteria 'notes = :notes'.
	 */
	@Transactional
	public List<Client> findWhereNotesEquals(String notes) throws ClientDaoException
	{
		try {
			return getJdbcTemplate().query("SELECT clientid, firstname, surname, idno, dob, title, mobile, hphone, wphone, email1, email2, postaddr1, postaddr2, postaddr3, postcode, physaddr1, physaddr2, physaddr3, notes, type, status, startdate, enddate, csys, cdate, usys, udate FROM " + getTableName() + " WHERE notes = ? ORDER BY notes", this,notes);
		}
		catch (Exception e) {
			throw new ClientDaoException("Query failed", e);
		}
		
	}

	/** 
	 * Returns all rows from the client table that match the criteria 'type = :type'.
	 */
	@Transactional
	public List<Client> findWhereTypeEquals(String type) throws ClientDaoException
	{
		try {
			return getJdbcTemplate().query("SELECT clientid, firstname, surname, idno, dob, title, mobile, hphone, wphone, email1, email2, postaddr1, postaddr2, postaddr3, postcode, physaddr1, physaddr2, physaddr3, notes, type, status, startdate, enddate, csys, cdate, usys, udate FROM " + getTableName() + " WHERE type = ? ORDER BY type", this,type);
		}
		catch (Exception e) {
			throw new ClientDaoException("Query failed", e);
		}
		
	}

	/** 
	 * Returns all rows from the client table that match the criteria 'status = :status'.
	 */
	@Transactional
	public List<Client> findWhereStatusEquals(String status) throws ClientDaoException
	{
		try {
			return getJdbcTemplate().query("SELECT clientid, firstname, surname, idno, dob, title, mobile, hphone, wphone, email1, email2, postaddr1, postaddr2, postaddr3, postcode, physaddr1, physaddr2, physaddr3, notes, type, status, startdate, enddate, csys, cdate, usys, udate FROM " + getTableName() + " WHERE status = ? ORDER BY status", this,status);
		}
		catch (Exception e) {
			throw new ClientDaoException("Query failed", e);
		}
		
	}

	/** 
	 * Returns all rows from the client table that match the criteria 'startdate = :startdate'.
	 */
	@Transactional
	public List<Client> findWhereStartdateEquals(Date startdate) throws ClientDaoException
	{
		try {
			return getJdbcTemplate().query("SELECT clientid, firstname, surname, idno, dob, title, mobile, hphone, wphone, email1, email2, postaddr1, postaddr2, postaddr3, postcode, physaddr1, physaddr2, physaddr3, notes, type, status, startdate, enddate, csys, cdate, usys, udate FROM " + getTableName() + " WHERE startdate = ? ORDER BY startdate", this,startdate);
		}
		catch (Exception e) {
			throw new ClientDaoException("Query failed", e);
		}
		
	}

	/** 
	 * Returns all rows from the client table that match the criteria 'enddate = :enddate'.
	 */
	@Transactional
	public List<Client> findWhereEnddateEquals(Date enddate) throws ClientDaoException
	{
		try {
			return getJdbcTemplate().query("SELECT clientid, firstname, surname, idno, dob, title, mobile, hphone, wphone, email1, email2, postaddr1, postaddr2, postaddr3, postcode, physaddr1, physaddr2, physaddr3, notes, type, status, startdate, enddate, csys, cdate, usys, udate FROM " + getTableName() + " WHERE enddate = ? ORDER BY enddate", this,enddate);
		}
		catch (Exception e) {
			throw new ClientDaoException("Query failed", e);
		}
		
	}

	/** 
	 * Returns all rows from the client table that match the criteria 'csys = :csys'.
	 */
	@Transactional
	public List<Client> findWhereCsysEquals(String csys) throws ClientDaoException
	{
		try {
			return getJdbcTemplate().query("SELECT clientid, firstname, surname, idno, dob, title, mobile, hphone, wphone, email1, email2, postaddr1, postaddr2, postaddr3, postcode, physaddr1, physaddr2, physaddr3, notes, type, status, startdate, enddate, csys, cdate, usys, udate FROM " + getTableName() + " WHERE csys = ? ORDER BY csys", this,csys);
		}
		catch (Exception e) {
			throw new ClientDaoException("Query failed", e);
		}
		
	}

	/** 
	 * Returns all rows from the client table that match the criteria 'cdate = :cdate'.
	 */
	@Transactional
	public List<Client> findWhereCdateEquals(Date cdate) throws ClientDaoException
	{
		try {
			return getJdbcTemplate().query("SELECT clientid, firstname, surname, idno, dob, title, mobile, hphone, wphone, email1, email2, postaddr1, postaddr2, postaddr3, postcode, physaddr1, physaddr2, physaddr3, notes, type, status, startdate, enddate, csys, cdate, usys, udate FROM " + getTableName() + " WHERE cdate = ? ORDER BY cdate", this,cdate);
		}
		catch (Exception e) {
			throw new ClientDaoException("Query failed", e);
		}
		
	}

	/** 
	 * Returns all rows from the client table that match the criteria 'usys = :usys'.
	 */
	@Transactional
	public List<Client> findWhereUsysEquals(String usys) throws ClientDaoException
	{
		try {
			return getJdbcTemplate().query("SELECT clientid, firstname, surname, idno, dob, title, mobile, hphone, wphone, email1, email2, postaddr1, postaddr2, postaddr3, postcode, physaddr1, physaddr2, physaddr3, notes, type, status, startdate, enddate, csys, cdate, usys, udate FROM " + getTableName() + " WHERE usys = ? ORDER BY usys", this,usys);
		}
		catch (Exception e) {
			throw new ClientDaoException("Query failed", e);
		}
		
	}

	/** 
	 * Returns all rows from the client table that match the criteria 'udate = :udate'.
	 */
	@Transactional
	public List<Client> findWhereUdateEquals(Date udate) throws ClientDaoException
	{
		try {
			return getJdbcTemplate().query("SELECT clientid, firstname, surname, idno, dob, title, mobile, hphone, wphone, email1, email2, postaddr1, postaddr2, postaddr3, postcode, physaddr1, physaddr2, physaddr3, notes, type, status, startdate, enddate, csys, cdate, usys, udate FROM " + getTableName() + " WHERE udate = ? ORDER BY udate", this,udate);
		}
		catch (Exception e) {
			throw new ClientDaoException("Query failed", e);
		}
		
	}

	/** 
	 * Returns the rows from the client table that matches the specified primary-key value.
	 */
	public Client findByPrimaryKey(ClientPk pk) throws ClientDaoException
	{
		return findByPrimaryKey( pk.getClientid() );
	}

}
